<?php
/**
 * 统计游戏数据
 */
namespace App\Models\MainDB\Statistics;

use Illuminate\Database\Eloquent\Model;

class StatisticsGameData extends Model
{
    protected $table = 'ln_statistics_game_data';

    protected $primaryKey = 'id';

    protected $fillable = [
        'id', //主键id
        'date', //日期
        'game_no', //游戏序号
        'game_count', //游戏次数
        'people_count', //参与人数
        'input_gold', //投入金币
        'output_gold', //产出金币
    ];

    public $timestamps = false;

    public function add($date, $gameNo, $data)
    {
        $record = $this
            ->select('id')
            ->where('date', $date)
            ->where('game_no', $gameNo)
            ->first();
        if ($record) {
            $this->where('id', $record->id)->update($data);
        } else {
            $data['date'] = $date;
            $data['game_no'] = $gameNo;
            $this->insert($data);
        }
    }
}